package net.daum.webtoon.android.util;

import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;

/**
 * Network���� Class
 * 
 * @author geekprogramer@gmail.com
 * 
 */
public class ConnectivityUtil {
	private static final String TAG = ConnectivityUtil.class.getSimpleName();

	/**
	 * ��Ʈ��ũ�� ���� ������ �������� �˾ƿ´�.
	 * 
	 * @param context
	 * @return
	 */
	public static boolean isConnect(Context context) {
		ConnectivityManager cm = (ConnectivityManager) context
				.getSystemService(Context.CONNECTIVITY_SERVICE);
		NetworkInfo netInfo = cm.getActiveNetworkInfo();
		if (netInfo != null && netInfo.isConnectedOrConnecting()) {
			return true;
		}
		return false;
	}

	/**
	 * wifi�� ����� �������� �˾ƿ´�.
	 * 
	 * @param context
	 * @return
	 */
	public static boolean isWifiAvailable(Context context) {
		ConnectivityManager connectivityManager = (ConnectivityManager) context
				.getSystemService(Context.CONNECTIVITY_SERVICE);
		boolean bConnect = false;
		try {
			if (connectivityManager == null) {
				return false;
			}

			NetworkInfo info = connectivityManager
					.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
			bConnect = (info.isAvailable() && info.isConnected());

		} catch (Exception e) {
			Logger.e(TAG, e.getMessage(), e);
			return false;
		}

		return bConnect;
	}
}
